package cn.wolfcode.p2p.base.domain;

import cn.wolfcode.p2p.base.util.BitStateUtil;
import cn.wolfcode.p2p.base.util.MaskUtil;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class UserInfo extends BaseDomain {
    private int version;//乐观锁

    private Long bitState = 0L;//用户状态码

    private String realName;//真实姓名

    private String idNumber;//身份证号码

    private String phoneNumber;//手机号码

    private Long realAuthId;//实名认证ID

    private Long videoAuthId;//视频认证ID

    private String email;//邮箱

    private SystemDictionaryItem incomeGrade;//收入情况

    private SystemDictionaryItem marriage;//婚姻情况

    private SystemDictionaryItem kidCount; //子女情况

    private SystemDictionaryItem educationBackground;//学历情况

    private SystemDictionaryItem houseCondition;//住房情况

    //用户填写基本资料状态码
    public boolean isHasBasicInfo(){
        return BitStateUtil.hasState(this.bitState,BitStateUtil.HAS_BASIC_INFO);
    }

    //用户实名认证状态码
    public boolean isHasRealAuth(){
        return BitStateUtil.hasState(this.bitState,BitStateUtil.HAS_REAL_AUTH);
    }

    //视频认证状态码
    public boolean isHasVideoAuth(){
        return BitStateUtil.hasState(this.bitState,BitStateUtil.HAS_VIDEO_AUTH);
    }

    //邮箱认证状态码
    public boolean getHasBindEmail(){
        return BitStateUtil.hasState(this.bitState,BitStateUtil.OP_BIND_EMAIL);
    }

    //借款申请认证正在审核中的状态码
    public boolean isHasBidRequestApplyProcess(){
        return BitStateUtil.hasState(this.bitState,BitStateUtil.HAS_BIDREQUEST_APPLY_PROCESS);
    }

    //所有状态
    public boolean isCanBorrow(){
        return isHasBasicInfo() && isHasRealAuth() && isHasVideoAuth();
    }

    /**
     * 给当前用户指定的状态码
     */
    public void addState(Long state){
        this.bitState = BitStateUtil.addState(this.bitState,state);
    }

    /**
     * 移除当前用户指定的状态码
     */
    public void removeState(Long state){
        this.bitState = BitStateUtil.removeState(this.bitState,state);
    }

    public String getAnonymousRealName() {
        return MaskUtil.getAnonymousRealName(realName);
    }

    public String getIdNumber() {
        return MaskUtil.getAnonymousIdNumber(idNumber);
    }
}
